package ui;

import utils.AnimationFactory;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;

import com.ui.R;

public class LoadingActivity extends Activity{	
	private ImageView transFileImage = null;
	
	public static LoadingActivity loadingActivity;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_loading);
		
		loadingActivity=this;
		
		//view initialisation
		transFileImage = (ImageView)findViewById(R.id.logo);
				
		//animation fadeIn
	    Animation fadeIn = AnimationFactory.selectanimation(loadingActivity, 4);
		fadeIn.setAnimationListener(new AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) {

			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {

			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				Animation animLoad = AnimationFactory.selectanimation(loadingActivity, 22);
				transFileImage.startAnimation(animLoad);
				
				animLoad.setAnimationListener(new AnimationListener() {
					
					@Override
					public void onAnimationStart(Animation animation) {
						
					}
					
					@Override
					public void onAnimationRepeat(Animation animation) {

					}
					
					@Override
					public void onAnimationEnd(Animation animation) {
						Animation fadeOut = AnimationFactory.selectanimation(loadingActivity, 28);
						transFileImage.startAnimation(fadeOut);
						
						fadeOut.setAnimationListener(new AnimationListener() {
							
							@Override
							public void onAnimationStart(Animation animation) {
								
							}
							
							@Override
							public void onAnimationRepeat(Animation animation) {

							}
							
							@Override
							public void onAnimationEnd(Animation animation) {
								transFileImage.setVisibility(View.INVISIBLE);
								startActivity(new Intent(LoadingActivity.this,MainActivity.class));
				                finish();
							}
						});
						transFileImage.startAnimation(fadeOut);
					}
				});
				transFileImage.startAnimation(animLoad);
			}
		});
		transFileImage.startAnimation(fadeIn);
	}
	
	@Override
    public void onResume() {
        super.onResume();        
    }
	
	@Override
    public void onPause() {
        super.onPause();
    }
	
}

